package com.lzy.cloud.member.controller;

import com.lzy.cloud.member.dtos.MemberCouponDto;
import com.lzy.cloud.member.facade.MemberCouponFacade;
import com.lzy.cloud.member.remote.dtos.BaseCouponDto;
import com.lzy.cloud.member.request.MemberCouponRequest;
import com.lzy.cloud.member.service.MemberCouponService;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by WIN7 on 2018/5/30.
 */
@RestController
@RequestMapping("/member/coupon")
public class MemberCouponController {

    @Autowired
    MemberCouponFacade memberCouponFacade;

    @Autowired
    MemberCouponService memberCouponService;

    /**
     * @Title: 添加会员卡券
     * @param: @return
     * @return: Result
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result add(MemberCouponRequest memberCouponRequest) {
        Ensure.that(memberCouponRequest).isNotNull("00010001");
        Long id = memberCouponService.add(DozerUtils.map(memberCouponRequest, MemberCouponDto.class));
        Ensure.that(id).isNotNull("00030002");
        return new Result();
    }

    /**
     * 根据会员id查询会员卡券
     * @param memberId
     * @return
     */
    @RequestMapping(value = "/find/car/rent/by/member/id/{memberId}", method = RequestMethod.GET)
    public Result findCarRentByMemberId(@PathVariable("memberId") Long memberId){
        Ensure.that(memberId).isNotNull("00010001");
        List<BaseCouponDto> list = memberCouponFacade.findCarRentByMemberId(memberId);
        return new Result(list);
    }

    /**
     * 根据卡券id查询
     * @param couponId
     * @return
     */
    @RequestMapping(value = "/find/by/coupon/id/{couponId}", method = RequestMethod.GET)
    public Result findByCouponId(@PathVariable("couponId") Long couponId){
        Ensure.that(couponId).isNotNull("00010001");
        MemberCouponDto memberCouponDto = memberCouponFacade.findByCouponId(couponId);
        return new Result(memberCouponDto);
    }
}
